package com.example.administrator.yuejian2.fragment;


import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;

import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian2.R;
import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.adapter.ClubAdapter;
import com.example.administrator.yuejian2.adapter.MyAttentionClubAdapter;
import com.example.administrator.yuejian2.bean.ClubBean;
import com.example.administrator.yuejian2.bean.MyAttentionClubBean;
import com.example.administrator.yuejian2.model.MyAttentionClubModel;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class MyAttentionClubFragment extends Fragment {

    private RecyclerView recyclerView;
    private SwipeRefreshLayout swipeRefreshLayout;
    private SharedPreferences sp;
    private MyAttentionClubAdapter adapter;
    private RecyclerView.LayoutManager layoutManager;
    private RetrofitListener<List<MyAttentionClubBean>> listener;

    private String u_id;
    public MyAttentionClubFragment() {

    }

    private void  myAttentionClub()
    {
        MyAttentionClubModel myAttentionClubModel=new MyAttentionClubModel();
        myAttentionClubModel.getMyAttentionClub(u_id,listener);
    }


    private void initView(View view)
    {
        recyclerView=view.findViewById(R.id.my_attention_club);
        swipeRefreshLayout=view.findViewById(R.id.refreshLayout);
        swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light,
                android.R.color.holo_orange_light, android.R.color.holo_green_light);
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                
            }
        });
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        listener=new RetrofitListener<List<MyAttentionClubBean>>() {
            @Override
            public void onSuccess(List<MyAttentionClubBean> myAttentionClubBeans, int flag) {
                        adapter.getMyAttentionClubList(myAttentionClubBeans);
            }

            @Override
            public void onFail() {

            }
        };
        View view= inflater.inflate(R.layout.fragment_my_attention_club, container, false);
        initView(view);
        sp = getActivity().getSharedPreferences("user_id", Context.MODE_PRIVATE);
        u_id = sp.getString("userid", null);
        layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        adapter = new MyAttentionClubAdapter(getActivity());
        recyclerView.setAdapter(adapter);
        myAttentionClub();

        return view;
    }

}
